package com.example.zlloggingservice.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * @Author zhenliu（孙凌岳）
 * @Description AI生成-操作日志数据库实体
 * @Date 2025/6/19 14:56
 * @Version 1.0
 */
@Data
@NoArgsConstructor
@TableName("operation_log")
@ApiModel(value = "OperationLog", description = "数据库操作日志实体")
public class OperationLog {

    @ApiModelProperty(value = "日志主键ID", example = "1")
    @TableId(value = "oper_id", type = IdType.INPUT)
    private Long operId;

    @ApiModelProperty(value = "操作用户ID", example = "1234567890")
    private Long userId;

    @ApiModelProperty(value = "用户名", example = "zhenliu")
    private String username;

    @ApiModelProperty(value = "操作行为（如 update_user）", required = true, example = "update_user")
    private String action;

    @ApiModelProperty(value = "请求URL", example = "/api/user/123")
    private String url;

    @ApiModelProperty(value = "请求IP地址", example = "192.168.0.1")
    private String ip;

    @ApiModelProperty(value = "操作详情（如修改字段内容）", example = "{\"field\":\"email\",\"old\":\"a@example.com\",\"new\":\"b@example.com\"}")
    private String detail;

    @ApiModelProperty(value = "操作状态（0成功，1失败）", example = "0")
    private Integer status;

    @ApiModelProperty(value = "操作时间", example = "2025-06-16T10:00:00")
    private LocalDateTime operTime;

    @Builder
    public OperationLog(Long operId, Long userId, String username, String action, String url, String ip, String detail, Integer status, LocalDateTime operTime) {
        this.operId = operId;
        this.userId = userId;
        this.username = username;
        this.action = action;
        this.url = url;
        this.ip = ip;
        this.detail = detail;
        this.status = status;
        this.operTime = operTime;
    }
}
